package cn.com.util;

import java.sql.Date;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.TimeZone;

public class TimeUtil {

    public static Timestamp getNowTimestamp(){
        Timestamp timestamp=new Timestamp(System.currentTimeMillis());
        return timestamp;
    }

    public static Timestamp getTodayZero(){
        return new Timestamp(getTodayZero(getNowTime()));
    }

    public static Timestamp getTodayTwelve(){
        return new Timestamp(getTodayTwelve(getNowTime()));
    }

    public static Long getTokenExp(){
//        返回一个月之后凌晨4点的时间戳
        return getTodayTwelve(getNowTime())+30*24*60*60*1000+4*60*60*1000;
    }
    public static Long getNowTime(){
        return System.currentTimeMillis();
    }

    public static Long getZero(){
        return getNowTime()/(1000*3600*24)*(1000*3600*24)- TimeZone.getDefault().getRawOffset();
    }

    public static Long getTwelve(){
        return getZero()+24*60*60*1000-1;
    }

    public static Long getTodayZero(Long time){
        return time/(1000*3600*24)*(1000*3600*24)- TimeZone.getDefault().getRawOffset();
    }

    public static String getTodayDate(Long time){
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date date=new java.util.Date(getTodayZero(time));
        return dateFormat.format(date);
    }

    public static Long getTodayTwelve(Long time){
        return  getTodayZero(time)+24*60*60*1000-1;
    }

    public static boolean judgeOneday(Long time1,Long time2){
        Long zero=getTodayZero(time1);
        Long twelve=getTodayTwelve(time1);
        return zero<time2&&time2<twelve;
    }

    public static String pares2String(Long time){
        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        time=time+120000L;
        java.util.Date date=new java.util.Date(time);
        return format.format(date);
    }
}
